import type { App } from "vue";
import { createPinia } from "pinia";
// 引入 pinia-plugin-persistedstate 插件，用于持久化存储
import persistedState from "pinia-plugin-persistedstate";
import { PiniaColada, PiniaColadaQueryHooksPlugin } from "@pinia/colada";

export function setupPinia(app: App) {
  const pinia = createPinia();
  // 配置 pinia
  pinia.use(persistedState);
  // 安装 pinia
  app.use(pinia);
  // 安装 PiniaColada
  app.use(PiniaColada, {
    queryOptions: {
      gcTime: 1000 * 60 * 10,
      staleTime: 1000 * 60 * 5,
    },
    plugins: [
      PiniaColadaQueryHooksPlugin({
        onError(error, entry) {
          console.log(error, entry);
        },
        onSuccess(data, entry) {
          console.log(data, entry);
        },
      }),
    ],
  });
}

export * from "./types";
